
import {ajax} from "@/utils/ajax.js"

export const getList=({id,genre,pageNo=1})=>{
	return ajax({
		url:'/commentInfo/bizList',
		data:{
			businessId:id,
			businessType:genre,
			pageNo,
			pageSize:5 
		}
	})
}

export const remove = async (ids)=>{
	if (remove.lock) {
		throw new Error('正在请求中')
	}
	try {
		remove.lock = true;
		const res = await ajax({
			url: '/commentInfo/delete',
			data: {
				ids
			}
		})
		return res;
	} catch (e) {
		throw e
	} finally {
		remove.lock = false;
	}
}

export const addReply = async ({
	id,
	genre,
	content,
	pid='',
	...rest
})=>{
	if (addReply.lock) {
		throw new Error('正在请求中')
	}
	try {
		addReply.lock = true;
		const res = await ajax({
			url: '/commentInfo/addReply',
			data: {
				businessId:id,
				businessType:genre,
				content,
				parentId:pid,
				...rest
			}
		})
		return res;
	} catch (e) {
		throw e
	} finally {
		addReply.lock = false;
	}
}


export const add = async ({
	id,
	genre,
	content,
	...rest
})=>{
	if (add.lock) {
		throw new Error('正在请求中')
	}
	try {
		add.lock = true;
		const res = await ajax({
			url: '/commentInfo/add',
			data: {
				businessId:id,
				businessType:genre,
				content,
				...rest
			}
		})
		return res;
	} catch (e) {
		throw e
	} finally {
		add.lock = false;
	}
}
